<template>
  <div>
    <a-card :bordered="false">
      <f-search-form :more="true" @searchHandler="searchHandler">
        <f-search-form-item label="供应商" name="supplierId" type="select" :data="api.supplier.list" valueKey="supplierId" label-key="supplierName"/>
        <f-search-form-item label="药品名称" name="drugsName"/>
        <f-search-form-item label="自营状态" name="ownerState" slot="advanced"/>

      </f-search-form>
      <f-table ref="table" rowKey="drugsId" :columns="columns" :multiple="false" :operator="operator" :params="queryParam" :api="api.drugs">
         <span slot="ownerState" slot-scope="text, record, index">
            <a-tag color="#108ee9" v-if="text==0">否</a-tag>
            <a-tag color="#f50" v-if="text==1">是</a-tag>
        </span>
        <span slot="drugsState" slot-scope="text, record, index">
            <a-tag color="#108ee9" v-if="text==0">已禁用</a-tag>
            <a-tag color="#f50" v-if="text==1">已启用</a-tag>
        </span>
        <span slot="floorPriceType" slot-scope="text, record, index">
            <a-tag color="#108ee9" v-if="text==1">结算价</a-tag>
            <a-tag color="#f50" v-if="text==2">成本价</a-tag>
        </span>
        <span slot="action" slot-scope="text, record">
          <template>
            <a @click="$refs.drawer.showDrawer(record)">编辑</a>
            <a-divider type="vertical"/>
          </template>
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down"/></a>
            <a-menu slot="overlay">
              <a-menu-item v-if="$auth('table.delete')">
                <a href="javascript:;" @click="$refs.table.del(record)">删除</a>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>
      </f-table>
      <drugs-drawer ref="drawer"></drugs-drawer>
    </a-card>
  </div>
</template>
<script>
  import drugsDrawer from './drugs_drawer.vue'
  import api from './js/api'

  export default {
    name: 'TableList',
    components: {
      drugsDrawer
    },
    data() {
      let me = this
      //操作按钮
      let operator = []
      operator.push({
        name: '添加',
        icon: 'plus',
        that: this,
        handler: function(table, that) {
          that.$refs.drawer.showDrawer()
        }
      })
      operator.push({
        name: '删除',
        icon: 'delete',
        batch: true,
        handler: function(table) {
          table.remove()
        }
      })
      return {
        api: Object.assign(api, this.api),
        //列表初始化查询参数
        queryParam: {},
        // 表头
        columns: [
          {
            title: '#',
            width: '60',
            align: 'center',
            customRender: (text, record, index) => index + 1
          },
          {
            title: '供应商',
            align: 'center',
            dataIndex: 'supplierName'
          },
          {
            title: '药品名称',
            align: 'center',
            dataIndex: 'drugsName'
          },
          {
            title: '规格',
            align: 'center',
            dataIndex: 'drugsSpec'
          },
          {
            title: '单位',
            align: 'center',
            dataIndex: 'drugsUnit'
          },
          {
            title: '自营',
            align: 'center',
            dataIndex: 'ownerState',
            scopedSlots: { customRender: 'ownerState' }
          },
          {
            title: '默认销售价',
            align: 'center',
            dataIndex: 'drugsPrice'
          },
          {
            title: '全局结算价',
            align: 'center',
            dataIndex: 'settlePrice'
          },
          {
            title: '无批号成本价',
            align: 'center',
            dataIndex: 'costPrice'
          },
          {
            title: '底价方式',
            align: 'center',
            dataIndex: 'floorPriceType',
            scopedSlots: { customRender: 'floorPriceType' }
          },
          {
            title: '状态',
            align: 'center',
            dataIndex: 'drugsState',
            scopedSlots: { customRender: 'drugsState' }
          },
          {
            title: '操作',
            align: 'center',
            scopedSlots: { customRender: 'action' }
          }
        ],
        operator: operator
      }
    },
    created() {
    },
    methods: {}
  }
</script>
